package date_;

import java.util.Arrays;

/**
 * @author wly
 * @version V1.0.0
 * @date 2022/12/24 14:02
 */
public class Homework01 {
    public static void main(String[] args) {
        try {
            String res = reverse("abcdef", 1, 04);
            System.out.println(res);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }

    public static String reverse(String str, int start, int end){
        if (!(str != null && start >= 0 && end > start && end < str.length())){
            throw new RuntimeException("参数不正确!");
        }
        char[] chars = str.toCharArray();
        char[] copy = Arrays.copyOf(chars, str.length());
        int p1 = start;
        int p2 = end;
        while (p1 < p2){
            char temp = chars[p1];
            copy[p1] = copy[p2];
            copy[p2] = temp;
            p1++;
            p2--;
        }

        String res = new String(copy);
        return res;
    }
}
